

	<!-- 可变效果区 -->
	<div class="main ">

		<div class="row">
			<div class="col-lg-12">
				<h3 class="page-header"><i class="fa fa-indent"></i>分类列表</h3>

			</div>
		</div>


        <div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h2><i class="fa fa-table red"></i><span class="break"></span><strong>列表</strong></h2>
						<div class="panel-actions">
							<a href="table.html#" class="btn-setting"><i class="fa fa-rotate-right"></i></a>
							<a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>
							<a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>
						</div>
					</div>
					<div class="panel-body">
						<table class="table table-bordered table-striped table-condensed table-hover">
							  <thead>
								  <tr>
								     <th width="150">ID</th>
									 <th width="500">名称</th>
									 <th width="300">pid</th>
									 <th width="150">操作</th>
								  </tr>
							  </thead>
							  <tbody>
							    <?php foreach($cate as $k=>$v){

							    ?>
								<tr pid="<?php echo $v['pid']?>">
									<td height="35"><?php echo $v['id']?></td>
                                    <td class="db_edit">
                                       <button  level=0 id="<?php echo $v['id']?>" class="btn btn-default" type="button"><i class="fa fa-arrows"></i></button>
                                       <?php echo $v['name']?></td>
                                    <td class="db_edit"><?php echo $v['pid']?></td>

									<td>
										<a href="index.php?c=cate&a=edit&admin=1&id=<?php echo $v['id']?>" title="编辑" class="btn btn-info">
											<i class="fa fa-edit "></i>
										</a>
										<a href="index.php?c=cate&a=del&admin=1&id=<?php echo $v['id']?>"  title="删除" class="btn btn-danger del">
											<i class="fa fa-trash-o "></i>
										</a>
								    </td>
								</tr>
								<?php }?>
							  </tbody>
						 </table>
						 <ul class="pagination">




						  </ul>
					</div>
				</div>
			</div><!--/col-->
		</div><!--/row-->



	</div>
	<!-- end: Content -->
	<br><br><br>

	<script src="resources/admin/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript">
	    $(function(){
            $('tbody').on('click','.btn',function(){

            	var obj = $(this);

            	var tr_obj = $(this).parent().parent();

            	var id = $(this).attr('id'); //获取自定义属性的id值

                level = parseInt($(this).attr('level'))+1;
                var move = 40*level;

                if('fa fa-arrows'==$(this).find('i').attr('class')){

                	$(this).find('i').removeClass().addClass('fa fa-arrows-h');

                	$.ajax({
                		type:'get',
                		url:'index.php?c=cate&a=list&admin=1&id='+id,
                		dataType:'json',
                		success:function(json){
                			var html = '';

                			for (i in json) {
                				html+='<tr pid='+id+'>';
									html+='<td height="35">'+json[i].id+'</td>';
	                                html+='<td class="db_edit" style="padding-left:'+move+'px">';
	                                   html+='<button level="'+level+'" id="'+json[i].id+'" class="btn btn-default"><i class="fa fa-arrows"></i></button>&nbsp'+json[i].name+'</td>';
	                                html+='<td class="db_edit">'+json[i].pid+'</td>';

									html+='<td>';
										html+='<a href="index.php?c=cate&a=edit&admin=1&id='+json[i].id+'" title="编辑" class="btn btn-info">';
											html+='<i class="fa fa-edit "></i>';
										html+='</a>';
										html+='<a href="index.php?c=cate&a=del&admin=1&id='+json[i].id+'"  title="删除" class="btn btn-danger del">';
											html+='<i class="fa fa-trash-o "></i>';
										html+='</a>';
								    html+='</td>';
								html+='</tr>';

                			};

                			html+='<tr style="display:none" pid='+id+'></tr>';
                			// obj=>button; parent=>td; parent=>tr
                			tr_obj.after(html);

                		}
                	})
                }else{
                	$(this).find('i').removeClass().addClass('fa fa-arrows');

                	var pid = tr_obj.attr('pid');

                	console.log('tr[pid='+pid+']');

                	tr_obj.nextUntil('tr[pid='+pid+']').remove();
                }
            })
	    })







			$('tbody').on('click','.del',function(){
				if(!confirm('确定删除？')){
					return false;
				}
				var url = $(this).attr('href');//抓取a标签的路径

                $.ajax({
                	type:'get',
                	url:url,
                	success:function(json){
                		if(json>0){
                			if(!confirm('您删除的选项有下一级选项，是否删除？')){
                				return false;
                			}
                		}

                		location.href=url;

                	}
                })


				return false;
			})


	</script>
